package jdbc;

import java.sql.*;

public class LoginDemo {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();) {
            LoginUserInfo loginUserInfo = InputUtil.getInputObject(new LoginUserInfo(), "欢迎登录宝贝~~");
            String sql = "SELECT id,username,password,nickname,age FROM userinfo WHERE username = '"+loginUserInfo.getUsername()+"' AND password = '"+loginUserInfo.getPassword()+"'";
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            if (resultSet.next()) {
                String nickname = resultSet.getString("nickname");
                System.out.println("欢迎回来，" + nickname + "宝贝~！");
            } else {
                System.out.println("登陆失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
